//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.quickserver.util.data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.quickserver.net.model.GB26875SetUp;
import org.quickserver.net.model.GBServerData;
import org.quickserver.net.model.GBServerDataAll;
import org.quickserver.net.server.ClientHandler;

public class ReadUtil {
    public ReadUtil() {
    }

    public static Map<String, Object> sendRead(String str, String uniqueCode, Date date, int type) {
        try {
            Object obj = GBServerDataAll.handlerMap.get(uniqueCode);
            if (obj == null) {
                return ReturnUtil.Error("此传输装置未连接，操作失败");
            } else {
                ClientHandler handler = (ClientHandler)obj;
                GBServerData ec = (GBServerData)handler.getClientData();
                if (ec == null) {
                    return ReturnUtil.Error("此传输装置未连接，操作失败");
                } else {
                    int serialNumber = ec.getSerialNumber() + 1;
                    List<GB26875SetUp> serialNumberList = ec.getSerialNumberList();
                    List<String> ss = new ArrayList();

                    for(int i = 0; i < serialNumberList.size(); ++i) {
                        ss.add(((GB26875SetUp)serialNumberList.get(i)).getSerialNumber());
                    }

                    String serialNumber16New;
                    for(boolean isHaveSerialNumber = true; isHaveSerialNumber; isHaveSerialNumber = dataProcessing.isHaveSerialNumber(ss, serialNumber16New)) {
                        --serialNumber;
                        serialNumber16New = dataProcessing.decimalToHex(serialNumber);
                        serialNumber16New = dataProcessing.addZeroForNum(serialNumber16New, 4);
                    }

                    serialNumber16New = dataProcessing.decimalToHex(serialNumber);
                    serialNumber16New = dataProcessing.addZeroForNum(serialNumber16New, 4);
                    if (date == null) {
                        date = new Date();
                    }

                    String[] dates = dataProcessing.getDateTime16(date);
                    String datesStr = "";

                    for(int i = 0; i < dates.length; ++i) {
                        datesStr = datesStr + dates[i];
                    }

                    String xjmStr = serialNumber16New + "0101" + datesStr + "000000000889000000088888" + str;
                    String xjm = dataProcessing.crc_8(xjmStr);
                    String hm = "4040" + xjmStr + xjm + "2323";
                    GB26875SetUp gs = new GB26875SetUp();
                    gs.setSerialNumber(serialNumber16New);
                    gs.setType(type);
                    gs.setHex(hm);
                    System.out.println("发送命令--" + type + "-----" + hm);
                    serialNumberList.add(gs);
                    ec.setSerialNumberList(serialNumberList);
                    handler.sendClientBinary(dataProcessing.hexStrToByteArray(hm));
                    boolean flag = false;
                    Map<String, Object> map = null;

                    for(int i = 0; i < 5; ++i) {
                        Thread.sleep(1000L);
                        List<GB26875SetUp> sL = ec.getSerialNumberList();

                        for(int j = 0; j < sL.size(); ++j) {
                            GB26875SetUp gsu = (GB26875SetUp)sL.get(j);
                            if (gsu.getSerialNumber().equals(serialNumber16New) && gsu.isOk()) {
                                flag = gsu.isTrue();
                                map = gsu.getDataMap();
                                sL.remove(j);
                                break;
                            }
                        }
                    }

                    if (flag) {
                        return ReturnUtil.Success("操作成功", map);
                    } else {
                        return ReturnUtil.Error("操作失败");
                    }
                }
            }
        } catch (Exception var24) {
            return ReturnUtil.Error("操作失败");
        }
    }
}
